<?php
include_once('inc/functions.inc.php');

if (!isEmpty(getParam('operation'))) {

    switch (getParam('operation')) {
        case 'filtro': {
                fntAcademicoAsignacionNotasFiltro($db);
                break;
            }
        case 'contenido': {
                fntAcademicoAsignacionNotasContenido($db);
                break;
            }
        case 'secciones': {
                fntAcademicoAsignacionNotasContenidoSecciones($db);
                break;
            }
        case 'materias': {
                fntAcademicoAsignacionNotasContenidoMaterias($db);
                break;
            }
        case 'estudiantes': {
                // fntAcademicoAsignacionNotasContenidoEstudiantes($db);
                fntAcademicoAsignacionNotasReporte($db);
                break;
            }
        case 'reporte': {
                fntAcademicoAsignacionNotasReporte($db);
                break;
            }
        case 's': {
                fntAcademicoAsignacionNotasGrabar($db);
                break;
            }
        case 'cuentas': {
                fntAcademicoAsignacionNotasContabilidadGetCuentasUltimoNivel($db);
                break;
            }
    }
    die();
}

function fntAcademicoAsignacionNotasFiltro($db) {
    //VARIBLES
    $strId = "";
    $strQuery = "";
    $arrInfo = array();
    $strCodigo = "";
    $strNombre = "";
    $strSelected = "";
    //VARIBLES
    ?>
    <script type="text/javascript">
        var intFilaPadres = 0;
    </script>
    <br>
    <br>
    <div style="width: 100px; height: 30px; float: left;"><b>Catedratico</b></div>
    <div style="width: 900px; height: 30px; float: left;">
        <select name="txtAcademicoAsignacionNotas_FK-CATEDRATICO" id="txtAcademicoAsignacionNotas_FK-CATEDRATICO">
            <option value=""></option>
            <?php
            $strQuery = "SELECT * FROM cllg_teacher WHERE STATUS = '1'";
            $qTMP = $db->query($strQuery);
            while ($rTMP = $db->fetch_array($qTMP)) {
                ?>
                <option value="<?php echo $rTMP["ID"]; ?>"><?php echo $rTMP["ID"] . " - " . htmlentities($rTMP["FIRST_NAME"] . " " . $rTMP["LAST_NAME"]); ?></option>
                <?php
            }
            $db->free_result($qTMP);
            ?>
        </select>
    </div>
    <p>
    <style>
        .ui-button { margin-left: -1px; }
        .ui-button-icon-only .ui-button-text { padding: 0.01em; } 
        .ui-autocomplete-input { margin: 0; padding: 0.0em 0 0.0em 0.0em; }
    </style>
    <script language="javascript" type="text/javascript">
        (function( $ ) {
            $.widget( "ui.combobox", {
                _create: function() {
                    var self = this,
                    select = this.element.hide(),
                    selected = select.children( ":selected" ),
                    value = selected.val() ? selected.text() : "";
                    var input = this.input = $( "<input>" )
                    .insertAfter( select )
                    .val( value )
                    .css("width", 300)
                    .autocomplete({
                        delay: 0,
                        minLength: 0,
                        source: function( request, response ) {
                            var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
                            response( select.children( "option" ).map(function() {
                                var text = $( this ).text();
                                if ( this.value && ( !request.term || matcher.test(text) ) )
                                    return {
                                        label: text.replace(
                                        new RegExp(
                                        "(?![^&;]+;)(?!<[^<>]*)(" +
                                            $.ui.autocomplete.escapeRegex(request.term) +
                                            ")(?![^<>]*>)(?![^&;]+;)", "gi"
                                    ), "<strong>$1</strong>" ),
                                        value: text,
                                        option: this
                                    };
                            }) );
                        },
                        select: function( event, ui ) {  
                            ui.item.option.selected = true;
                            self._trigger( "selected", event, {
                                item: ui.item.option
                            });
                            $("[name='hdnAcademicoAsignacionNotas_Id']").val("");
                            fntAcademicoAsignacionNotasContenido();
                            //fntAcademicoAsignacionNotasReporte();
                        },
                        change: function( event, ui ) {
                            if ( !ui.item ) {
                                var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
                                valid = false;
                                select.children( "option" ).each(function() {
                                    if ( $( this ).text().match( matcher ) ) {
                                        this.selected = valid = true;
                                        return false;
                                    }
                                });
                                if ( !valid ) {
                                    // remove invalid value, as it didn't match anything
                                    $( this ).val( "" );
                                    select.val( "" );
                                    input.data( "autocomplete" ).term = "";
                                    return false;
                                }
                            }
                        }
                    })
                    .addClass( "ui-widget ui-widget-content ui-corner-left" );

                    input.data( "autocomplete" )._renderItem = function( ul, item ) {
                        return $( "<li></li>" )
                        .data( "item.autocomplete", item )
                        .append( "<a>" + item.label + "</a>" )
                        .appendTo( ul );
                    };

                    this.button = $( "<button type='button'>&nbsp;</button>" )
                    .attr( "tabIndex", -1 )
                    .attr( "title", "Show All Items" )
                    .insertAfter( input )
                    .button({
                        icons: {
                            primary: "ui-icon-triangle-1-s"
                        },
                        text: false
                    })
                    .removeClass( "ui-corner-all" )
                    .addClass( "ui-corner-right ui-button-icon" )
                    .click(function() {
                        // close if already visible
                        if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
                            input.autocomplete( "close" );
                            return;
                        }

                        // work around a bug (likely same cause as #5265)
                        $( this ).blur();

                        // pass empty string as value to search for, displaying all results
                        input.autocomplete( "search", "" );
                        input.focus();
                    });
                },

                destroy: function() {
                    this.input.remove();
                    this.button.remove();
                    this.element.show();
                    $.Widget.prototype.destroy.call( this );
                }
            });
        })( jQuery );

        $(function() {
            $("#txtAcademicoAsignacionNotas_FK-CATEDRATICO").combobox();
        });
    </script>
    <script type="text/javascript">
        $(function() {
            $("[name='txtAcademicoAsignacionNotas_FK-CATEDRATICO']").change( function(){
                $("[name='hdnAcademicoAsignacionNotas_Id']").val("");
                fntAcademicoAsignacionNotasContenido();
                fntAcademicoAsignacionNotasReporte();
            });
        });
    </script>
    <?php
}

function fntAcademicoAsignacionNotasContenido($db) {
    //VARIBLES
    $strId = "";
    $strQuery = "";
    $arrInfo = array();
    $strCodigo = "";
    $strNombre = "";
    $strSelected = "";
    //VARIBLES

    $strId = isset($_POST["hdnAcademicoAsignacionNotas_Id"]) ? $_POST["hdnAcademicoAsignacionNotas_Id"] : "";
    $strCatedratico = isset($_POST["txtAcademicoAsignacionNotas_FK-CATEDRATICO"]) ? $_POST["txtAcademicoAsignacionNotas_FK-CATEDRATICO"] : "";
    if (!empty($strId)) {
        $strQuery = "SELECT  FK_CATEDRATICO, FK_PERIODO, FK_GRADO, FK_SECCION, FK_ESTUDIANTE, NOTA, DATE_FORMAT(FECHA_ASIGNACION, '%d-%m-%Y') AS FECHA_ASIGNACION 
                    FROM    cllg_academico_notas_asignacion 
                    WHERE   ID = '{$strId}'";
        $qTMP = $db->query($strQuery);
        while ($rTMP = $db->fetch_array($qTMP)) {
            $arrInfo = $rTMP;
        }
        $db->free_result($qTMP);
    }

    $strPeriodo = isset($arrInfo["FK_PERIODO"]) ? $arrInfo["FK_PERIODO"] : "";
    $strGrado = isset($arrInfo["FK_GRADO"]) ? $arrInfo["FK_GRADO"] : "";
    $strNota = isset($arrInfo["NOTA"]) ? $arrInfo["NOTA"] : "";
    $strSeccion = isset($arrInfo["FK_SECCION"]) ? $arrInfo["FK_SECCION"] : "";
    $strEstudiante = isset($arrInfo["FK_ESTUDIANTE"]) ? $arrInfo["FK_ESTUDIANTE"] : "";
    $strFechaAsignacion = isset($arrInfo["FECHA_ASIGNACION"]) ? $arrInfo["FECHA_ASIGNACION"] : "";
    $arrDias = array();
    $arrDia["DOMINGO"] = "DOMINGO";
    $arrDia["LUNES"] = "LUNES";
    $arrDia["MARTES"] = "MARTES";
    $arrDia["MIERCOLES"] = "MIERCOLES";
    $arrDia["JUEVES"] = "JUEVES";
    $arrDia["VIERNES"] = "VIERNES";
    $arrDia["SABADO"] = "SABADO";
    ?>
    <script type="text/javascript">
        var intFilaPadres = 0;
    </script>
    <br> 
    </p>
    <table width="1000" border="0">
        <tr>
            <td><table style="border:none<" width="100%" border="0" cellpadding="2" cellspacing="1">
                    <tr>
                        <td colspan="2"><label for="chck_verificador"><b>
                                    <input type="checkbox" value="1" checked="checked" name="chck_verificador" id="chck_verificador" />
                                    Actualizar si ya existe!</b></label></td>
                    </tr>
                    <tr>
                        <td width="22%"><b>
                                <label>No. Evaluaci&oacute;n</label>
                            </b></td>
                        <td width="78%"><select name="txtAcademicoAsignacionNotas_no-evaluacion" style="width: 200px;">
                                <option value="1">Primera</option>
                                <option value="2">Segunda</option>
                                <option value="3">Tercera</option>
                                <option value="4">Cuarta</option>
                                <option value="5">Quinta</option>
                                <option value="6">Sexta</option>
                            </select></td>
                    </tr>
                    <tr>
                        <td><b><label for="txtAcademicoAsignacionNotas_fk-periodo">Periodo</label></b>&nbsp;</td>
                        <td><select name="txtAcademicoAsignacionNotas_fk-periodo" style="width: 200px;">
                                <option value=""></option>
    <?php
    $strQuery = "SELECT * FROM cllg_academico_periodos WHERE ACTIVO = 'Y'";
    $qTMP = $db->query($strQuery);
    while ($rTMP = $db->fetch_array($qTMP)) {
        $strSelected = ( $strPeriodo == $rTMP["ID"] ) ? "selected" : "";
        ?>
                                    <option value="<?php echo $rTMP["ID"]; ?>" <?php echo $strSelected; ?>><?php echo $rTMP["NOMBRE"]; ?></option>
                                    <?php
                                }
                                $db->free_result($qTMP);
                                ?>
                            </select></td>
                    </tr>
                    <tr>
                        <td><b><label for="txtAcademicoAsignacionNotas_fk-grado">Grado</label></b>&nbsp;</td>
                        <td><select name="txtAcademicoAsignacionNotas_fk-grado" style="width: 200px;">
                                <option value=""></option>
    <?php
    $strQuery = "SELECT  cllg_academico_grados.ID, cllg_academico_grados.CODIGO, cllg_academico_grados.NOMBRE 
                        FROM    cllg_academico_grados,
                                cllg_academico_catedraticos_asignacion
                        WHERE   cllg_academico_grados.ACTIVO = 'Y'
                        AND     cllg_academico_grados.ID = cllg_academico_catedraticos_asignacion.FK_GRADO
                        AND     cllg_academico_catedraticos_asignacion.FK_CATEDRATICO = '{$strCatedratico}'
                        GROUP   BY cllg_academico_grados.ID";

    $qTMP = $db->query($strQuery);
    while ($rTMP = $db->fetch_array($qTMP)) {
        $strSelected = ( $strGrado == $rTMP["ID"] ) ? "selected" : "";
        ?>
                                    <option value="<?php echo $rTMP["ID"]; ?>" <?php echo $strSelected; ?>><?php echo $rTMP["CODIGO"]; ?> - <?php echo $rTMP["NOMBRE"]; ?></option>
                                    <?php
                                }
                                $db->free_result($qTMP);
                                ?>
                            </select>&nbsp;</td>
                    </tr>
                    <tr>
                        <td><b><label for="txtAcademicoAsignacionNotas_fk-seccion">Sección</label></b>&nbsp;</td>
                        <td><div id="divAcademicoAsignacionNotasContenidoSeccion">
                                <select name="txtAcademicoAsignacionNotas_fk-seccion">
                                    <option value="0"></option>
    <?php
    $strQuery = "SELECT  * 
                        FROM    cllg_academico_secciones,
                                cllg_academico_grados_secciones 
                        WHERE   cllg_academico_secciones.ID = cllg_academico_grados_secciones.FK_SECCION
                        AND     cllg_academico_grados_secciones.FK_GRADO = '{$strGrado}'";
    $qTMP = $db->query($strQuery);
    while ($rTMP = $db->fetch_array($qTMP)) {
        $strSelected = ( $strSeccion == $rTMP["ID"] ) ? "selected" : "";
        ?>
                                        <option value="<?php echo $rTMP["ID"]; ?>" <?php echo $strSelected; ?> ><?php echo $rTMP["NOMBRE"]; ?></option>
                                        <?php
                                    }
                                    $db->free_result($qTMP);
                                    ?>
                                </select>        
                            </div></td>
                    </tr>
                    <tr>
                        <td><strong>Materia</strong></td>
                        <td><div id="divAcademicoAsignacionNotasContenidoMateria"></div></td>
                    </tr>
                    <tr>
                        <td><b>
                                <label>Fecha Asignación</label>
                            </b></td>
                        <td><input type="text" name="txtAcademicoAsignacionNotas_FECHA-ASIGNACION" value="<?php echo $strFechaAsignacion; ?>" style="text-align: center;" maxlength="10" /></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                </table></td>
        </tr>
    </table>
    &nbsp;
    <!--
    <div style="width: 100px; height: 30px; float: left;"><b>Estudiante</b></div>
    <div style="width: 900px; height: 30px; float: left;" id="divAcademicoAsignacionNotasContenidoEstudiante">
        <select name="txtAcademicoAsignacionNotas_FK-ESTUDIANTE">
            <option value="0"></option>
    <?php
    $strQuery = "SELECT  * 
                        FROM    cllg_student,
                                cllg_academico_estudiantes_asignacion 
                        WHERE   cllg_student.ID = cllg_academico_estudiantes_asignacion.FK_ESTUDIANTE
                        AND     cllg_academico_estudiantes_asignacion.FK_PERIODO = '{$strPeriodo}'
                        AND     cllg_academico_estudiantes_asignacion.FK_GRADO = '{$strGrado}'
                        AND     cllg_academico_estudiantes_asignacion.FK_SECCION = '{$strSeccion}'
                        ";
    /* $qTMP = $db->query($strQuery);
      while ( $rTMP = $db->fetch_array($qTMP) ) {
      $strSelected = ( $strEstudiante==$rTMP["ID"] ) ? "selected" : "";
      ?>
      <option value="<?php echo $rTMP["ID"]; ?>" <?php echo $strSelected; ?> ><?php echo $rTMP["FIRST_NAME"]." ".$rTMP["LAST_NAME"]; ?></option>
      <?php
      }
      $db->free_result($qTMP); */
    ?>
        </select>        
    </div>
    <div style="width: 100px; height: 30px; float: left;"><b>Nota</b></div>
    <div style="width: 900px; height: 30px; float: left;">
        <input type="text" name="txtAcademicoAsignacionNotas_NOTA" value="<?php echo $strNota; ?>" size="5" maxlength="5">
    </div>-->

    <script type="text/javascript" >
        $(function(){
            $("input[name='txtAcademicoAsignacionNotas_FECHA-ASIGNACION']").datepicker({
                changeMonth: true,
                changeYear: true,
                monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],
                dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'],
                dateFormat: 'dd-mm-yy'
            });
            $("input[name='txtAcademicoAsignacionNotas_FECHA-EXPIRACION']").datepicker({
                changeMonth: true,
                changeYear: true,
                monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],
                dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'],
                dateFormat: 'dd-mm-yy'
            });
            $("[name='txtAcademicoAsignacionNotas_fk-grado']").change( function () {
                fntAcademicoAsignacionNotasContenidoSeccion();
                fntAcademicoAsignacionNotasContenidoMateria();
                fntAcademicoAsignacionNotasContenidoEstudiantes();
            });
            $("[name='txtAcademicoAsignacionNotas_fk-seccion']").change( function () {
                //            fntAcademicoAsignacionNotasContenidoEstudiantes();
                fntAcademicoAsignacionNotasReporte();
            });    
        });
    </script>
    <?php
}

function fntAcademicoAsignacionNotasContenidoSecciones($db) {

    //VARIBLES
    $strId = "";
    $strQuery = "";
    //VARIBLES
    $strCatedratico = isset($_POST["txtAcademicoAsignacionNotas_FK-CATEDRATICO"]) ? $_POST["txtAcademicoAsignacionNotas_FK-CATEDRATICO"] : "";
    $strGrado = isset($_POST["txtAcademicoAsignacionNotas_fk-grado"]) ? $_POST["txtAcademicoAsignacionNotas_fk-grado"] : "";
    ?>
    <select name="txtAcademicoAsignacionNotas_fk-seccion">
        <option value="0"></option>
    <?php
    $strQuery = "SELECT  cllg_academico_secciones.ID, cllg_academico_secciones.NOMBRE 
                FROM    cllg_academico_secciones,
                        cllg_academico_grados_secciones,
                        cllg_academico_catedraticos_asignacion 
                WHERE   cllg_academico_secciones.ID = cllg_academico_grados_secciones.FK_SECCION
                AND     cllg_academico_grados_secciones.FK_GRADO = '{$strGrado}'
                AND     cllg_academico_secciones.ID = cllg_academico_catedraticos_asignacion.FK_SECCION
                AND     cllg_academico_catedraticos_asignacion.FK_CATEDRATICO = '{$strCatedratico}'
                GROUP   BY cllg_academico_secciones.ID";
    $qTMP = $db->query($strQuery);
    while ($rTMP = $db->fetch_array($qTMP)) {
        $strSelected = ( $strGrado == $rTMP["ID"] ) ? "selected" : "";
        ?>
            <option value="<?php echo $rTMP["ID"]; ?>"><?php echo $rTMP["NOMBRE"]; ?></option>
            <?php
        }
        $db->free_result($qTMP);
        ?>
    </select>
    <script type="text/javascript">
        $("[name='txtAcademicoAsignacionNotas_fk-seccion']").change( function () {
            fntAcademicoAsignacionNotasContenidoMateria();
            fntAcademicoAsignacionNotasContenidoEstudiantes();
        });
    </script>
    <?php
}

function fntAcademicoAsignacionNotasContenidoEstudiantes($db) {

    //VARIBLES
    $strId = "";
    $strQuery = "";
    //VARIBLES
    $strCatedratico = isset($_POST["txtAcademicoAsignacionNotas_FK-CATEDRATICO"]) ? $_POST["txtAcademicoAsignacionNotas_FK-CATEDRATICO"] : "";
    $strPeriodo = isset($_POST["txtAcademicoAsignacionNotas_fk-periodo"]) ? $_POST["txtAcademicoAsignacionNotas_fk-periodo"] : "";
    $strGrado = isset($_POST["txtAcademicoAsignacionNotas_fk-grado"]) ? $_POST["txtAcademicoAsignacionNotas_fk-grado"] : "";
    $strSeccion = isset($_POST["txtAcademicoAsignacionNotas_fk-seccion"]) ? $_POST["txtAcademicoAsignacionNotas_fk-seccion"] : "";
    ?>
    <select name="txtAcademicoAsignacionNotas_FK-ESTUDIANTE">
        <option value="0"></option>
    <?php
    $strQuery = "SELECT  cllg_student.ID, cllg_student.FIRST_NAME, cllg_student.LAST_NAME 
                    FROM    cllg_student,
                            cllg_academico_estudiantes_asignacion 
                    WHERE   cllg_student.ID = cllg_academico_estudiantes_asignacion.FK_ESTUDIANTE
                    AND     cllg_academico_estudiantes_asignacion.FK_PERIODO = '{$strPeriodo}'
                    AND     cllg_academico_estudiantes_asignacion.FK_GRADO = '{$strGrado}'
                    AND     cllg_academico_estudiantes_asignacion.FK_SECCION = '{$strSeccion}'
                    ";
    //drawDebug($strQuery);
    $qTMP = $db->query($strQuery);
    while ($rTMP = $db->fetch_array($qTMP)) {
        ?>
            <option value="<?php echo $rTMP["ID"]; ?>"><?php echo $rTMP["FIRST_NAME"] . " " . $rTMP["LAST_NAME"]; ?></option>
            <?php
        }
        $db->free_result($qTMP);
        ?>
    </select>
        <?php
    }

    function fntAcademicoAsignacionNotasContenidoMaterias($db) {

        //VARIBLES
        $strQuery = "";
        $arrAsignados = array();
        //VARIBLES
        $strCatedratico = isset($_POST["txtAcademicoAsignacionNotas_FK-CATEDRATICO"]) ? $_POST["txtAcademicoAsignacionNotas_FK-CATEDRATICO"] : "";
        $strPeriodo = isset($_POST["txtAcademicoAsignacionNotas_fk-periodo"]) ? $_POST["txtAcademicoAsignacionNotas_fk-periodo"] : "";
        $strGrado = isset($_POST["txtAcademicoAsignacionNotas_fk-grado"]) ? $_POST["txtAcademicoAsignacionNotas_fk-grado"] : "";
        $strSeccion = isset($_POST["txtAcademicoAsignacionNotas_fk-seccion"]) ? $_POST["txtAcademicoAsignacionNotas_fk-seccion"] : "";

        $strQuery = "SELECT  * 
                FROM    cllg_academico_catedraticos_asignacion 
                WHERE   cllg_academico_catedraticos_asignacion.FK_PERIODO  = '{$strPeriodo}'
                AND     cllg_academico_catedraticos_asignacion.FK_GRADO = '{$strGrado}'
                AND     cllg_academico_catedraticos_asignacion.FK_SECCION = '{$strSeccion}'";
        $qTMP = $db->query($strQuery);
        while ($rTMP = $db->fetch_array($qTMP)) {
            //$arrAsignados[$rTMP["FK_MATERIA"]] = $rTMP["FK_MATERIA"]; 
        }
        $db->free_result($qTMP);
        /* drawDebug($strQuery);
          drawDebug($arrAsignados); */
        $strQuery = "SELECT  cllg_academico_materias.*      
                FROM    cllg_academico_pensum,
                        cllg_academico_pensum_detail,
                        cllg_academico_materias,
                        cllg_academico_catedraticos_asignacion 
                WHERE   cllg_academico_pensum.ID = cllg_academico_pensum_detail.FK_PENSUM
                AND     cllg_academico_pensum.FK_PERIODO  = '{$strPeriodo}'
                AND     cllg_academico_pensum.FK_GRADO = '{$strGrado}'
                AND     cllg_academico_pensum_detail.FK_MATERIA = cllg_academico_materias.ID
                AND     cllg_academico_catedraticos_asignacion.FK_MATERIA = cllg_academico_materias.ID
                AND     cllg_academico_catedraticos_asignacion.FK_CATEDRATICO = '{$strCatedratico}' 
                AND     cllg_academico_catedraticos_asignacion.FK_SECCION = '{$strSeccion}' 
                GROUP   BY cllg_academico_catedraticos_asignacion.FK_MATERIA";
        $qTMP = $db->query($strQuery);
        //drawdebug($strQuery);
        ?>
    <select name="txtAcademicoAsignacionNotas_FK-MATERIA">
    <?php
    while ($rTMP = $db->fetch_array($qTMP)) {
        if (!isset($arrAsignados[$rTMP["ID"]])) {
            $strSelected = ( $strPeriodo == $rTMP["ID"] ) ? "selected" : "";
            ?>
                <option value="<?php echo $rTMP["ID"]; ?>"><?php echo $rTMP["NOMBRE"]; ?></option>
                <?php
            }
        }
        $db->free_result($qTMP);
        ?>
    </select>
        <?php
    }

    function fntAcademicoAsignacionNotasReporte($db) {
        //VARIBLES
        $strId = "";
        $strQuery = "";
        //VARIBLES
        $strCatedratico = isset($_POST["txtAcademicoAsignacionNotas_FK-CATEDRATICO"]) ? $_POST["txtAcademicoAsignacionNotas_FK-CATEDRATICO"] : "";
        $strPeriodo = isset($_POST["txtAcademicoAsignacionNotas_fk-periodo"]) ? $_POST["txtAcademicoAsignacionNotas_fk-periodo"] : "";
        $strGrado = isset($_POST["txtAcademicoAsignacionNotas_fk-grado"]) ? $_POST["txtAcademicoAsignacionNotas_fk-grado"] : "";
        $strSeccion = isset($_POST["txtAcademicoAsignacionNotas_fk-seccion"]) ? $_POST["txtAcademicoAsignacionNotas_fk-seccion"] : "";
        /*
          $strQuery = "SELECT CA.ID, CA.FK_CATEDRATICO, CA.FK_PERIODO, CA.FK_GRADO, CA.NOTA,
          DATE_FORMAT(CA.FECHA_ASIGNACION, '%d-%m-%Y') AS FECHA_ASIGNACION,
          T.FIRST_NAME, T.LAST_NAME,
          P.NOMBRE AS PERIODO,
          G.NOMBRE AS GRADO,
          S.NOMBRE AS SECCION,
          M.NOMBRE AS MATERIA,
          E.FIRST_NAME,
          E.LAST_NAME
          FROM    cllg_academico_notas_asignacion AS CA,
          cllg_teacher AS T,
          cllg_academico_periodos AS P,
          cllg_academico_grados AS G,
          cllg_academico_secciones AS S,
          cllg_academico_materias AS M,
          cllg_student AS E
          WHERE   CA.FK_CATEDRATICO = T.ID
          AND     CA.FK_PERIODO = P.ID
          AND     CA.FK_GRADO = G.ID
          AND     CA.FK_SECCION = S.ID
          AND     CA.FK_MATERIA = M.ID
          AND     CA.FK_ESTUDIANTE = E.ID
          AND     T.ID = '{$strCatedratico}'
          ORDER   BY CA.FK_PERIODO, CA.FK_GRADO "; */
        $strQuery = "SELECT  * 
                        FROM    cllg_student,
                                cllg_academico_estudiantes_asignacion 
                        WHERE   cllg_student.ID = cllg_academico_estudiantes_asignacion.FK_ESTUDIANTE
                        AND     cllg_academico_estudiantes_asignacion.FK_PERIODO = '{$strPeriodo}'
                        AND     cllg_academico_estudiantes_asignacion.FK_GRADO = '{$strGrado}'
                        AND     cllg_academico_estudiantes_asignacion.FK_SECCION = '{$strSeccion}'
                        ";
        $qTMP = $db->query($strQuery);
        $intNumRows = $db->num_rows;
        ?>
    <table width="100%" cellpadding="2" cellspacing="0" border="0" id="tblAcademicoAsignacionNotas">
        <thead>
            <tr>
                <th width="66%" align="left" ><b>Estudiante</b></th>
                <th width="34%" align="center" ><b>Nota</b></th>
            </tr>
        </thead>
        <tbody>
    <?php
    if ($intNumRows) {

        while ($rTMP = $db->fetch_array($qTMP)) {
            ?>
                    <tr align="left" id="<?php echo $rTMP["ID"]; ?>">
                        <td width="66%"><?php echo htmlentities($rTMP["FIRST_NAME"] . " " . $rTMP["LAST_NAME"]); ?></td>
                        <td width="34%" align="center">
                            <input type="hidden" name="_stud_<?php echo $rTMP["ID"]; ?>" value="<?php echo $rTMP["ID"]; ?>" size="10" />
                            <input  name="score_<?php echo $rTMP["ID"]; ?>" type="text" class="required number" id="score_<?php echo $rTMP["ID"]; ?>" value="0.00" size="10" maxlength="100" minlength="0" /></td>
                    </tr>        
            <?php
        }
    }
    $db->free_result($qTMP);
    ?>
        </tbody>
    </table>
    <script type="">
        //these two line adds the color to each different row
        $("#tblAcademicoAsignacionNotas tr:even").addClass("eventr");;
        $("#tblAcademicoAsignacionNotas tr:odd").addClass("oddtr");;
        //handle the mouseover , mouseout and click event
        $("#tblAcademicoAsignacionNotas tr").mouseover(function() {
        $(this).addClass("trover");
        }).mouseout(function() {
        $(this).removeClass("trover");
        });
        $("#frmAcademicoAsignacionNotas").validate();
        /*.click(function() {
        //$("tr[id!='"+$(this).attr("id")+"']").removeClass("trover");
        //$(this).addClass("trover");        
        //$(this).toggleClass("trclick");
        $("input[name='hdnAcademicoAsignacionNotas_Id']").val( $(this).attr("id") );
        fntAcademicoAsignacionNotasContenido();
        });*/
    </script>
    <?php
}

function fntAcademicoAsignacionNotasGrabar($db) {
    $log = "iniciando!";
    $strId = isset($_POST["hdnAcademicoAsignacionNotas_Id"]) ? $_POST["hdnAcademicoAsignacionNotas_Id"] : "";
    $strFields = "";
    $strValues = "";
    $scores = array();
    while ($arrPost = each($_POST)) {
        $arrExplode = explode("_", $arrPost["key"]);

        if ($arrExplode[0] == "score") {
            $i = explode("_", $arrPost["key"]);
            $scores[$i[1]] = $arrPost["value"];
        }
        if ($arrExplode[0] == "txtAcademicoAsignacionNotas") {
            if ($arrPost["key"] != "hdnAcademicoAsignacionNotas_Id") {

                if ($arrExplode[1] == "FECHA-ASIGNACION" || $arrExplode[1] == "FECHA-EXPIRACION") {
                    $arrTMP = array();
                    $arrTMP = explode("-", $arrPost["value"]);
                    krsort($arrTMP);
                    $arrPost["value"] = implode("-", $arrTMP);
                }

                if (empty($strId)) {
                    $strFields .= (empty($strFields)) ? "" : ",";
                    $strFields .= strtoupper(str_ireplace("-", "_", $arrExplode[1]));

                    $strValues .= empty($strValues) ? "" : ",";
                    $strValues .= "'{$arrPost["value"]}'";
                } else {
                    $strFields .= (empty($strFields)) ? "" : ",";
                    $strFields .= strtoupper(str_ireplace("-", "_", $arrExplode[1])) . " = '{$arrPost["value"]}'";
                }
            }
        }
    }
    print_r($scores);
    //patch para ingreso masivo
    $strFields.=",FK_ESTUDIANTE,NOTA";
    foreach ($scores as $k => $v) {
        $values = $strValues . ",$k,'$v'";
        $sql="INSERT INTO cllg_academico_notas_asignacion ({$strFields}) VALUES ({$values})";
        echo $sql;
        $db->query($sql);
        $log.="<br>" . $db->lastQuery;
    }
    /* if( empty($strId) ) {
      $db->query("INSERT INTO cllg_academico_notas_asignacion ({$strFields}) VALUES ({$strValues})");
      }else {
      $db->query("UPDATE cllg_academico_notas_asignacion SET {$strFields} WHERE ID = '{$strId}'");
      } */
}
?>